package org.absolutezero.client.presenter;

import javax.inject.Inject;

import org.absolutezero.client.events.RenderLoginEvent;
import org.absolutezero.client.events.RenderRegisterEvent;
import org.absolutezero.client.events.RenderWelcomeEvent;
import org.absolutezero.client.view.PageView;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasWidgets;


public class PageHeaderPresenter {

	
	private final PageView page;
	private final EventBus ebus;
	
	@Inject
	public PageHeaderPresenter(PageView page,
					EventBus ebus){
		
		this.page = page;
		this.ebus = ebus;
	}
	
	
	
	public void setNotLoggedHeaderButtons(){
		HasWidgets buttonsPnl = page.getHeaderButtons();
		
		Button loginBtn = new Button("Login", new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				ebus.fireEvent(new RenderLoginEvent());
			}
		});
		
		Button registerBtn = new Button("Register", new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				ebus.fireEvent(new RenderRegisterEvent());
			}
		});
		
		buttonsPnl.clear();
		buttonsPnl.add(loginBtn);
		buttonsPnl.add(registerBtn);
		
		
	}
	
	public void setLoggedHeaderButtons(){
		HasWidgets buttonsPnl = page.getHeaderButtons();
		
		Button logoutBtn = new Button("Logout", new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				ebus.fireEvent(new RenderWelcomeEvent());				
			}
		});
		
		buttonsPnl.clear();
		buttonsPnl.add(logoutBtn);
	}
	
	public void showNavigationMenu(){
		page.showRightPanel();
	}
	
	public void hideNavigationMenu(){
		page.hideRightPanel();
	}
}
